#ifndef FILEPROGRESSDISPLAY_H
#define FILEPROGRESSDISPLAY_H

#include <QWidget>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QTimer>
#include <QPropertyAnimation>
#include <QGraphicsOpacityEffect>
#include "filestatusiconmanager.h"

/**
 * 文件进度显示系统
 * 提供文件处理进度的可视化反馈
 */
class FileProgressDisplay : public QWidget
{
    Q_OBJECT

public:
    explicit FileProgressDisplay(QWidget* parent = nullptr);
    ~FileProgressDisplay();

    // 进度显示类型
    enum DisplayType {
        Minimal,        // 最小化显示（状态栏中的小控件）
        Compact,        // 紧凑显示（弹出式小窗口）
        Detailed        // 详细显示（完整进度对话框）
    };

    // 进度更新
    void updateFileProgress(const QString& fileName, int currentPage, int totalPages,
                           FileStatusIconManager::FileStatus status = FileStatusIconManager::FileStatus::Processing);
    void updateOverallProgress(int completedFiles, int totalFiles, const QString& operation = QString());
    void setEstimatedTimeRemaining(int seconds);

    // 显示控制
    void showProgress(const QString& title, DisplayType type = Compact);
    void hideProgress();
    void setDisplayType(DisplayType type);

    // 进度状态
    bool isVisible() const;
    void setProgress(int current, int total);
    void setStatusText(const QString& text);
    void setShowCancelButton(bool show);

signals:
    // 用户交互信号
    void cancelRequested();
    void detailsRequested();
    void minimizeRequested();

private slots:
    void onCancelClicked();
    void onDetailsClicked();
    void onMinimizeClicked();
    void updateDisplay();
    void onAnimationFinished();

private:
    // UI设置
    void setupUI();
    void setupMinimalUI();
    void setupCompactUI();
    void setupDetailedUI();

    // 布局管理
    void switchToDisplayType(DisplayType type);
    void arrangeComponents();
    void updateComponentVisibility();
    void setupMinimalLayout();
    void setupCompactLayout();
    void setupDetailedLayout();

    // 动画效果
    void showWithAnimation();
    void hideWithAnimation();
    void updateProgressAnimation();

    // 文本格式化
    QString formatTimeRemaining(int seconds);
    QString formatFileInfo(const QString& fileName, int currentPage, int totalPages);
    QString formatOverallProgress(int completed, int total, const QString& operation);

    // 主要组件
    DisplayType m_displayType;

    // 布局容器
    QVBoxLayout* m_mainLayout;
    QHBoxLayout* m_buttonLayout;

    // 显示组件
    QLabel* m_titleLabel;
    QLabel* m_fileInfoLabel;
    QLabel* m_statusLabel;
    QLabel* m_timeRemainingLabel;
    QProgressBar* m_fileProgressBar;
    QProgressBar* m_overallProgressBar;

    // 控制按钮
    QPushButton* m_cancelButton;
    QPushButton* m_detailsButton;
    QPushButton* m_minimizeButton;

    // 状态数据
    struct ProgressData {
        QString currentFileName;
        int currentPage = 0;
        int totalPages = 0;
        int completedFiles = 0;
        int totalFiles = 0;
        QString operation;
        QString statusText;
        int estimatedTimeSeconds = 0;
        FileStatusIconManager::FileStatus status = FileStatusIconManager::FileStatus::Processing;
        bool showCancel = true;
    } m_progressData;

    // 动画和效果
    QTimer* m_updateTimer;
    QPropertyAnimation* m_fadeAnimation;
    QGraphicsOpacityEffect* m_opacityEffect;

    // 显示状态
    bool m_isShowing = false;
    QString m_currentTitle;

    // 样式常量
    static const int ANIMATION_DURATION_MS = 300;
    static const int UPDATE_INTERVAL_MS = 100;
    static const int MIN_WIDTH_MINIMAL = 200;
    static const int MIN_WIDTH_COMPACT = 400;
    static const int MIN_WIDTH_DETAILED = 600;
};

#endif // FILEPROGRESSDISPLAY_H